<?php

namespace app\admin\service;


use app\model\Activity;

/**
 * @desc 抽奖活动
 * Class ActivityService
 * @package app\admin\service
 */
class ActivityService extends CommonService
{
    /**
     * @desc 获取开奖列表
     * @return array
     */
    public static function getPageList()
    {
        $list = Activity::getPageList([], '', 'status ASC id DESC');
        return $list;
    }

    /**
     * @desc 获取开奖机制
     * @return array
     */
    public static function getCycleType()
    {
        return Activity::$cycle_type;
    }

    public static function edit($request)
    {
        $data = $request['form'];
        if (!empty($data['start_time']) && !empty($data['end_time']))
        {
            $data['start_time'] = strtotime($data['start_time']);
            $data['end_time'] = strtotime($data['end_time']);
        }

        if (!empty($data['id']))
        {
            Activity::updateOne($data, ['id' => $data['id']]);
        } else {
            Activity::addOne($data);
        }
        return true;
    }

    public static function getById($id)
    {
        $data = Activity::getById($id);
        $data['start_time'] = date('Y-m-d H:i:s', $data['start_time']);
        $data['end_time'] = date('Y-m-d H:i:s', $data['end_time']);
        return $data;
    }
}